#include "ValueType.h"

ValueType
value_fetch_type (ObjectStringApplication* str)
{
        char ch;
        bool has_fquote = false;
        if (!str)
                return VALUE_TYPE_ERROR;
        object_string_application_rewind (str);

        ch = object_string_application_iter (str);
        if (ch == '\0')
                return VALUE_TYPE_ERROR;
        if (ch == '{') {
                has_fquote = true;
                ch         = object_string_application_iter (str);
                if (ch == '\0')
                        return VALUE_TYPE_ERROR;
        }
reiter:
        switch (ch) {
        case '.':
                return VALUE_TYPE_DATE;
        case '-': {
                if (has_fquote)
                        return VALUE_TYPE_RANGE;
                else
                        return VALUE_TYPE_TEXT;
        }
        case '\0':
                return VALUE_TYPE_NUMBER;
        default: {
                if ((ch < '0' || ch > '9') && ch != '}' && ch != ',')
                        return VALUE_TYPE_TEXT;
                break;
        }
        }
        ch = object_string_application_iter (str);
        goto reiter;
}
